package cfg

import (
	"encoding/json"
	"io/ioutil"
	"log"
	"strings"
)

var ConfigData *Tables

func init() {
	configData, err := NewTables(Loader)
	if err != nil {
		log.Fatalf("readconfig is wrong message is %v", err)
	}
	ConfigData = configData
}
func Loader(file string) ([]map[string]interface{}, error) {
	file = strings.ToLower(file)
	if bytes, err := ioutil.ReadFile("./data/" + file + ".json"); err != nil {
		return nil, err
	} else {
		jsonData := make([]map[string]interface{}, 0)
		if err = json.Unmarshal(bytes, &jsonData); err != nil {
			return nil, err
		}
		return jsonData, nil
	}
}
